package com.sakura.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sakura.commonutils.R;
import com.sakura.eduservice.entity.EduCourse;
import com.sakura.eduservice.entity.chapter.ChapterVo;
import com.sakura.eduservice.entity.frontvo.CourseFrontQuery;
import com.sakura.eduservice.entity.frontvo.CourseWebVo;
import com.sakura.eduservice.service.EduChapterService;
import com.sakura.eduservice.service.EduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "CourseFrontController",description = "前台课程列表的显示")
@RestController
@RequestMapping("/eduservice/coursefront")
public class CourseFrontController {
    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduChapterService chapterService;



    @ApiOperation("分页显示课程列表")
    @PostMapping("list/{page}/{limit}")
    public R pageList(@ApiParam(name = "page",value = "当前页码",required = true)
                          @PathVariable Long page,
                      @ApiParam(name = "limit",value = "每页显示的数量",required = true)
                              @PathVariable Long limit,
                      @ApiParam(name = "courseQuery",value = "查询对象",required = false)
                                  @RequestBody(required = false) CourseFrontQuery courseQuery){
        return R.ok().data(courseService.pageListWeb(new Page<EduCourse>(page,limit),courseQuery));
    }

    @ApiOperation("根据ID查询课程")
    @GetMapping("{courseId}")
    public R getById(@PathVariable String courseId){
        //查询课程信息和讲师信息
        CourseWebVo courseWebVo = courseService.selectInfoWebById(courseId);
        //查询当前课程的章节信息
        List<ChapterVo> chapterVoList = chapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoList",chapterVoList);
    }



}
